package com.daguchuangyi.erp_android.productlist.widget;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.daguchuangyi.erp_android.R;

/**
 * Created by lijianjian on 2018/3/12.
 */

public class AccountQuitDialog extends DialogFragment implements View.OnClickListener {
    private TextView mCancelBtn;
    private TextView mConfirmBtn;

    private OnDeleteChooseListener mOnDeleteChooseListener;

    public void setOnDeleteChooseListener(OnDeleteChooseListener onDeleteChooseListener) {
        mOnDeleteChooseListener = onDeleteChooseListener;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_quite_confirm_dialog, container, false);
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        mCancelBtn = (TextView) view.findViewById(R.id.cancel_btn);
        mConfirmBtn = (TextView) view.findViewById(R.id.confirm_btn);
        mCancelBtn.setOnClickListener(this);
        mConfirmBtn.setOnClickListener(this);
    }


    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            dialog.getWindow().setLayout((int) (dm.widthPixels * 0.75), ViewGroup.LayoutParams.WRAP_CONTENT);
        }
    }


    @Override
    public void onDestroyView() {
        mOnDeleteChooseListener = null;
        super.onDestroyView();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cancel_btn:
                if (mOnDeleteChooseListener != null) {
                    mOnDeleteChooseListener.onDeleteCancel();
                }
                dismiss();
                break;
            case R.id.confirm_btn:
                if (mOnDeleteChooseListener != null) {
                    mOnDeleteChooseListener.onDeleteConfirm();
                }
                dismiss();
                break;
        }
    }

    public interface OnDeleteChooseListener {
        public void onDeleteConfirm();

        public void onDeleteCancel();
    }
}
